package 剑指Offer._1120;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/7/18 12:00
 * 二进制中1的个数
 * 算法：位运算
 */
public class _15 {

    public int hammingWeight(int n) {
        int ans = 0;
        for (int i = 0; i < 32; i++) {
            if ((n >> i & 1) == 1) ++ans;
        }
        return ans;
    }

}
